<template>
	<view>
		<!-- d顶部标题 -->
		<!-- <view class="head_text">
			<text>修改企业信息</text>
			<image src="../../static/client/back.png"
				style="width: 20rpx;height: 36rpx;position: absolute;left: 30rpx;top: 63rpx;" @click="back()"></image>
		</view> -->
		<form action="">
			<!-- 企业名称 -->
			<view class="info_item">
				<text>企业名称</text>
				<input placeholder="请输入企业名称" v-model="editCompanyFormData.company_name" style="margin-top: 39rpx;"
					placeholder-style="font-size:30rpx" />
			</view>
			<view class="info_item">
				<text>是否打开侧重部门</text>
				<switch style="transform: scale(0.7);margin-left: 50rpx;" :checked="isChecked" @change="departmentChange" />
				
			</view>
			<!-- 企业LOGO -->
			<view class="info_item">
				<view>企业LOGO</view>
				<image v-if="editCompanyFormData.company_logo" :src="editCompanyFormData.company_logo "
					style="border-radius: 39rpx; width: 78rpx;height: 78rpx;margin-top: 29rpx;">
					<image v-else src="/static/client/tianjia.png"
						style="width: 78rpx;height: 78rpx;margin-top: 29rpx;">
					</image>
					<view style="position: absolute;top: 80rpx; left: 100rpx;" @click="selectImg">
						<image src="/static/firm/icon_sc.png" style="width: 25rpx; height: 19rpx;">
						</image>
						<text style="font-size: 20rpx; color: #128BF1;margin-left: 10rpx;">点击上传文件</text>
					</view>
			</view>
			<!-- 企业描述 -->
			<view class="info_item" style="border-bottom: 0;">
				<text>企业描述</text>
				<textarea v-model="editCompanyFormData.content" class="texta" placeholder="请输入企业简介"
					placeholder-style="font-size:28rpx;" />
			</view>
			<!-- 底部按钮 -->
			<view class="bottom">
				<button class="bottom_btn" style="background: #CCCCCC; width: 380rpx;" form-type="reset">取消</button>
				<button class="bottom_btn"
					style="background: linear-gradient(0deg, #037CE3, #2EB3FF); margin-top: -88rpx;margin-left: 50%;"
					form-type="submit" @click="handleSubmitEditCompany">确定</button>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: '',
				member_id: '',
				company_id: '',
				isChecked:true,
				LoginCompanyName: '',
				LoginCompanyLogo: '',
				department_model:1,
				editCompanyFormData: {
					company_name: '',
					company_logo: '',
					content: '',
				},
			}
		},
		onLoad() {
			this.token = uni.getStorageSync('btlh_process_token') || ''
			this.member_id = uni.getStorageSync('btlh_process_member_id') || ''
			this.company_id = uni.getStorageSync('bthl_process_LoginCompanyId') || ''

			this.LoginCompanyName = uni.getStorageSync('bthl_process_LoginCompanyName') || ''
			if (this.LoginCompanyName) {
				this.editCompanyFormData.company_name = this.LoginCompanyName
			}
			this.LoginCompanyLogo = uni.getStorageSync('bthl_process_LoginCompanyLogo') || ''
			if (this.LoginCompanyLogo) {
				this.editCompanyFormData.company_logo = this.LoginCompanyLogo
			}
			this.department_model = uni.getStorageSync('cache_department_model');
			if(this.department_model == 1){
				this.isChecked = true
			}else{
				this.isChecked = false
			}
		},
		methods: {
			// 是否打开侧重部门department_model（int）1是，0否；
			departmentChange(){
				this.isChecked = !this.isChecked
				if(this.department_model == 1){
					this.department_model = 0
				}else{
					this.department_model = 1
				}
				
				
			},
			// 点击提交修改企业
			async handleSubmitEditCompany() {
				const {
					data: res
				} = await this.$myRequest({
					url: 'Company/update',
					method: 'POST',
					data: {
						member_id: this.member_id,
						token: this.token,
						company_id: this.company_id,
						department_model:this.department_model,
						company_name: this.editCompanyFormData.company_name,
						company_logo: this.editCompanyFormData.company_logo,
						content: this.editCompanyFormData.content,
					},

				})
				if (res.code != 200) return uni.showToast({
					title: res.datas.msg,
					icon: 'none'
				})
				uni.showToast({
					title: res.datas.msg,
					icon: 'none'
				})

				
				uni.setStorage({
					key: 'cache_department_model',
					data: this.department_model
				})
				uni.setStorage({
					key: 'bthl_process_LoginCompanyName',
					data: this.editCompanyFormData.company_name
				})
				uni.setStorage({
					key: 'bthl_process_LoginCompanyLogo',
					data: this.editCompanyFormData.company_logo
				})
				uni.navigateBack({
					delta:1
				})
			},
			// 上传企业logo
			selectImg() {
				var that = this
				uni.chooseImage({
					count: 1, // 最多可以选择的图片张数，默认9
					sizeType: ['original', 'compressed'], //original 原图，compressed 压缩图，默认二者都有
					sourceType: ['album', 'camera'], //album 从相册选图，camera 使用相机，默认二者都有。如需直接开相机或直接选相册，请只使用一个选项
					success: async (res) => {
						const tempFilePaths = res.tempFilePaths;
						that.phone = res.tempFilePaths[0]
						uni.uploadFile({
							url: 'https://control.sxpz.vip/index.php/AppApi/User/uploadImg',
							filePath: tempFilePaths[0],
							name: 'file',
							formData: {
								'member_id': this.member_id,
								'token': this.token,
							},
							success: uploadFileRes => {
								const result = JSON.parse(uploadFileRes.data)
								this.editCompanyFormData.company_logo = result.datas.img_url
							}
						})
					}
				});
			},
			/* 
			点击返回 
			 */
			back() {
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style>
	.bottom {
		width: 100%;
		height: 88rpx;
		position: absolute;
		bottom: 0;
	}

	.bottom_btn {
		width: 375rpx;
		height: 88rpx;
		margin-left: 0;
		border-radius: 0;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.texta {
		width: 690rpx;
		height: 305rpx;
		background: #F7F7F7;
		margin-top: 30rpx;

	}

	.info_item {
		width: 690rpx;
		height: auto;
		border-bottom: 1rpx solid #E3E3E3;
		margin-left: 30rpx;
		margin-top: 44rpx;
		position: relative;
	}

	.head_text {
		width: 100%;
		height: 128rpx;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		line-height: 160rpx;
		text-align: center;
		border-bottom: 19rpx solid #F7F7F7;
	}
</style>
